package com.flyoil.petromp.mvp_p.SearchCertainPresenter;

import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchBaseModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchCourseFinanceModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchGoodsApproveModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchGoodsDateExamineModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchGoodsDemandModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchGoodsExamineModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchGoodsOrderModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchCoursePlanModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchServiceApproveModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchServiceDemandModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchServiceExamineModel;
import com.flyoil.petromp.mvp_m.SearchCertainModel.SearchServiceOrderModel;
import com.flyoil.petromp.mvp_p.Listener.BasePresenter;
import com.flyoil.petromp.mvp_v.ListUIView.BaseUIView;
import com.flyoil.petromp.utils.OrderUtl.OrderListUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by songzhiyin on 2017/11/1.
 * 流程列表展示搜索结果的逻辑处理类
 */

public class SearchCertainPresenter implements BasePresenter {
    private BaseUIView view;
    private String type;
    private List<String> data_edt;
    private SearchBaseModel model;
    private Map<String, Object> map = new HashMap<>();

    public SearchCertainPresenter(BaseUIView view, String type) {
        this.view = view;
        this.type = type;
        model = new SearchCoursePlanModel();
        initModel();
    }

    @Override
    public void onsucced(List data) {
        view.updataToUI(data);
    }

    @Override
    public void initNetworkData(Map<String, Object> map) {

    }

    public void initNetworkData(List<String> data_edt) {
        this.data_edt = data_edt;
        model.loadNetworkData(getMapFromList(), this);
    }

    public void initOrderStatus(int order_status) {
       //transformStatusEQ: 0 流转中 ,1 已完成 ,2 待撤销 ,3 已冻结
        switch (order_status) {
            case 0:
                map.put("transformStatusEQ", 1);
                break;
            case 1:
                map.put("transformStatusEQ", 0);
                break;
            case 2:
                map.put("isDraftEQ", true);

                break;
            case 3:
                map.put("transformStatusEQ", 2);
                break;
        }
    }

    private Map<String, Object> getMapFromList() {
        switch (type) {
            case OrderListUtil.PLAN://物资计划单
                if (data_edt.size() == 6) {
                    map.put("snLK", data_edt.get(0));
                    map.put("subjectLK", data_edt.get(1));
                    map.put("applicantNameLK", data_edt.get(2));
                    map.put("deptNameLK", data_edt.get(3));
                    map.put("submitDateGTE", data_edt.get(4));
                    map.put("submitDateLTE", data_edt.get(5));
                }
                break;
            case OrderListUtil.GOODS_DEMAND://物资需求单
                if (data_edt.size() == 6) {
                    map.put("snLK", data_edt.get(0));
                    map.put("demandNameLK", data_edt.get(1));
                    map.put("applicantNameLK", data_edt.get(2));
                    map.put("deptNameLK", data_edt.get(3));
                    map.put("submitDateGTE", data_edt.get(4));
                    map.put("submitDateLTE", data_edt.get(5));
                }
                break;
            case OrderListUtil.GOODS_APPROVE://物资审批单
                if (data_edt.size() == 6) {
                    map.put("snLK", data_edt.get(0));
                    map.put("demandNameLK", data_edt.get(1));
                    map.put("applicantNameLK", data_edt.get(2));
                    map.put("supplierNameLK", data_edt.get(3));
                    map.put("submitDateGTE", data_edt.get(4));
                    map.put("submitDateLTE", data_edt.get(5));
                }
                break;
            case OrderListUtil.GOODS_ORDER://物资订单
                if (data_edt.size() == 6) {
                    map.put("snLK", data_edt.get(0));
                    map.put("demandSnLK", data_edt.get(1));
                    map.put("applicantNameLK", data_edt.get(2));
                    map.put("supplierNameLK", data_edt.get(3));
                    map.put("orderDateGTE", data_edt.get(4));
                    map.put("orderDateLTE", data_edt.get(5));
                }
                break;
            case OrderListUtil.GOODS_EXAMINE://物资验收单
                if (data_edt.size() == 4) {
                    map.put("snLK", data_edt.get(0));
                    map.put("supplierNameLK", data_edt.get(1));
                    map.put("submitDateGTE", data_edt.get(2));
                    map.put("submitDateLTE", data_edt.get(3));
                }
                break;
            case OrderListUtil.GOODS_DATE_EXAMINE://物资质保期验收单
                if (data_edt.size() == 3) {
                    map.put("snLK", data_edt.get(0));
                    map.put("submitDateGTE", data_edt.get(1));
                    map.put("submitDateLTE", data_edt.get(2));
                }
                break;
            case OrderListUtil.SERVICE_DEMAND://服务需求单
                if (data_edt.size() == 6) {
                    map.put("snLK", data_edt.get(0));
                    map.put("nameLK", data_edt.get(1));
                    map.put("usernameLK", data_edt.get(2));
                    map.put("deptNameLK", data_edt.get(3));
                    map.put("createdTimeGT", data_edt.get(4));
                    map.put("createdTimeLTE", data_edt.get(5));
                }
                break;
            case OrderListUtil.SERVICE_APPROVE://服务任务审批单
                if (data_edt.size() == 6) {
                    map.put("snLK", data_edt.get(0));
                    map.put("nameLK", data_edt.get(1));
                    map.put("usernameLK", data_edt.get(2));
                    map.put("supplierNameLK", data_edt.get(3));
                    map.put("createdTimeGT", data_edt.get(4));
                    map.put("createdTimeLTE", data_edt.get(5));
                }
                break;
            case OrderListUtil.SERVICE_ORDER://服务订单
                if (data_edt.size() == 6) {
                    map.put("snLK", data_edt.get(0));
                    map.put("serviceRequirementSnLK", data_edt.get(1));
                    map.put("usernameLK", data_edt.get(2));
                    map.put("supplierNameLK", data_edt.get(3));
                    map.put("createdTimeGT", data_edt.get(4));
                    map.put("createdTimeLTE", data_edt.get(5));
                }
                break;
            case OrderListUtil.SERVICE_EXAMINE://服务验收
                if (data_edt.size() == 4) {
                    map.put("snLK", data_edt.get(0));
                    map.put("supplierNameLK", data_edt.get(1));
                    map.put("createdTimeGT", data_edt.get(2));
                    map.put("createdTimeLTE", data_edt.get(3));
                }
                break;
            case OrderListUtil.FINANCE://付款申请单
                if (data_edt.size() == 2) {
                    map.put("snLK", data_edt.get(0));
                    map.put("institutionLK", data_edt.get(1));
                }
                break;

        }
        return map;
    }

    /**
     * 初始化model
     */
    private void initModel() {
        switch (type) {
            case OrderListUtil.PLAN://物资计划单
                model = new SearchCoursePlanModel();
                break;
            case OrderListUtil.GOODS_DEMAND://物资需求单
                model = new SearchGoodsDemandModel();
                break;
            case OrderListUtil.GOODS_APPROVE://物资审批单
                model = new SearchGoodsApproveModel();
                break;
            case OrderListUtil.GOODS_ORDER://物资订单
                model = new SearchGoodsOrderModel();
                break;
            case OrderListUtil.GOODS_EXAMINE://物资验收单
                model = new SearchGoodsExamineModel();
                break;
            case OrderListUtil.GOODS_DATE_EXAMINE://物资质保期验收单
                model = new SearchGoodsDateExamineModel();
                break;
            case OrderListUtil.SERVICE_DEMAND://服务需求单
                model = new SearchServiceDemandModel();
                break;
            case OrderListUtil.SERVICE_APPROVE://服务任务审批单
                model = new SearchServiceApproveModel();
                break;
            case OrderListUtil.SERVICE_ORDER://服务订单
                model = new SearchServiceOrderModel();
                break;
            case OrderListUtil.SERVICE_EXAMINE://服务验收单
                model = new SearchServiceExamineModel();
                break;
            case OrderListUtil.FINANCE://付款申请单
                model = new SearchCourseFinanceModel();
                break;

        }
    }
}
